import java.util.*;

/**
 * @Author: YCKOKO
 * @Date: 2023-04-03
 * @Time:09:09
 * @Description:
 */
public class demo4 {
    public static List<Integer> path = new ArrayList<>();
    public static List<List<Integer>> ret = new ArrayList<>();
    public static int sum = 0;

    public static void main(String[] args) {
        int[] nums = {-1,0,1,2,-1,-4};
        List<List<Integer>> ret = threeSum(nums);
        System.out.println(ret);
    }

    public static List<List<Integer>> threeSum(int[] nums) {
        Arrays.sort(nums);
        backTracking(nums,3,0);
        return ret;
    }

    public static void backTracking(int[] nums,int len,int startIndex){
        if(path.size() == len){
            if(sum == 0  && !ret.contains(path)){
                ret.add(path);
                sum = 0;
            }
            return;
        }
        for(int i = startIndex; i < nums.length; i++){
            path.add(nums[i]);
            sum += nums[i];
            backTracking(nums,len,i+1);
            sum -= nums[i];
            path.remove(i);
        }
    }
}
